﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;

namespace uzing
{
    public class uzCTcpListenerSync
    {
        TcpListener listener;

        public int Open(int Port)
        {
            listener = new TcpListener(IPAddress.Any, 0);
            listener.Start();
            var endPoint = (IPEndPoint)listener.LocalEndpoint;
            var retVal = endPoint.Port;
            return retVal;
        }

        public uzCTcpClientSync AcceptTcpClient()
        {
            var uzClient = new uzCTcpClientSync();
            var tcpClient = listener.AcceptTcpClient();
            uzClient.RegisterClient(tcpClient);
            return uzClient;
        }
    }
}
